//
//  ByViewProductDetailCommentHeader.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/2.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewProductDetailCommentHeader.h"

#import "ByProductCommentListVC.h"      // 评论列表


@implementation ByViewProductDetailCommentHeader
{
    UILabel *_countLabel;
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    _countLabel = [[UILabel alloc] init];
    _countLabel.text = @"";
    _countLabel.font = FONT(14);
    _countLabel.textAlignment = NSTextAlignmentLeft;
    _countLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_countLabel];
    
    UILabel *lookLabel = [[UILabel alloc] init];
    lookLabel.text = @"查看全部";
    lookLabel.font = FONT(14);
    lookLabel.textAlignment = NSTextAlignmentLeft;
    lookLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lookLabel];
    
    UIImageView *arrowView = [UIImageView new];
    arrowView.image = [UIImage imageNamed:@"双箭头"];
    [self.contentView addSubview:arrowView];
    
    // 线条
    UIView *line = [UIView new];
    line.backgroundColor = BY_LINE_COLOR;
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.equalTo(@1);
    }];        
    
    [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.bottom.equalTo(@0);
    }];
    [lookLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(@0);
        make.right.equalTo(arrowView.mas_left).offset(-5);
    }];
    [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.right.equalTo(@-10);
        make.centerY.equalTo(@0);
    }];
}

- (void)setModel:(ByModelProductDetail *)model {
    
    _model = model;
    _countLabel.text = [NSString stringWithFormat:@"商品评价(%li条)", model.commentCount];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    ByProductCommentListVC *vc = [ByProductCommentListVC new];
    vc.detailModel = _model;
    [((ByBaseVC *)self.viewController) by_normalPush:vc hasNavi:true];
}

@end
